﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BGCOP.CAVTOP.COMMON;

namespace BGCOP.CAVTOP.WINFORMS
{
    public partial class frmCamara : Form
    {
        public PictureBox u;
        private LogCls LogF = new LogCls();

        public frmCamara()
        {
            InitializeComponent();
        }

        private void frmCamara_Load(object sender, EventArgs e)
        {
            try
            {
                
                button1.Focus();
                webCam1.Start();
                LogF.FilePath = System.IO.Path.GetDirectoryName(
      System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

            }
            catch (Exception ex)
            {

                MessageBox.Show("Error al iniciar el dispositivo de captura! " + ex.Message , Properties.Settings.Default.Titulo,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                LogF.Evento = "Error: " + ex.Message;
                LogF.AddEvent();
            }
        }

        private void frmCamara_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                webCam1.Stop();
            }
            catch (Exception ex)
            {

                this.Text = "Error " + ex.Message; throw;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //guarda la imagen

                u.BackgroundImage = webCam1.Imagen;
                webCam1.Stop();
            }
            catch (Exception ex)
            {

                //throw;
                //this.Text = "Error " + ex.Message; throw;
            }

            this.Close();
        }
    }
}
